<?php
function excel_view_page(){
	$out='';
	$out .= theme('excel');
	$out .= l(t('导出Excel'),'admin/structure/excel/excel_out');
	return $out;
}
function get_form_search($form_state){
	/*
	$form['name']=array(
		'#title'=>'损失事件名称',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>'',
	);
	*/
	$form['line']=array(
		'#title'=>'业务条线',
		'#type'=>'select',
		'#options'=>array('any',1,2,3,4),

		'#default_value'=> array('any'),
	);
	$form['rating']=array(
		'#title'=>'风险等级',
		'#type'=>'select',
		'#options'=>array('any',1,2,3,4),
		'#default_value'=> array('any'),
	);
	$form['submit']=array(
		'#type'=>'submit',
		'#value'=>'Apply',
		'#submit'=>array('search_form_excel_submit'),
	);
	$form['reset']=array(
		'#type'=>'submit',
		'#value'=>'reset',
		'#submit'=>array('search_form_excel_reset'),
	);
	return $form;
}
function search_form_excel_submit($form,$form_state){
	$callback_url = current_path(); 
	$args=array();
	if($form_state['values']['line']!=0){
		$args['query']['line']=$form_state['values']['line'];
	}
	if($form_state['values']['rating']!=0){
		$args['query']['rating']=$form_state['values']['rating'];
	}
  	drupal_goto($callback_url,$args) ; 
}
function search_form_excel_reset($form,$form_state){   
  	drupal_goto('admin/structure/excel') ; 
}

function excel_edit_page($form_state){
	$id=$_GET['id'];
	$result=db_select('excel','e')
	->condition('id',$id)
	->fields('e')
	->execute()
	->fetchAssoc();
	$form['name']=array(
		'#title'=>'损失事件名称',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['name'],
	);
	$form['status']=array(
		'#title'=>'事件状态',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['status'],
	);
	$form['rating']=array(
		'#title'=>'风险等级',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['rating'],
	);
	$form['description']=array(
		'#title'=>'损失事件描述',
		'#type'=>'textarea',
		'#required'=>TRUE,
		'#default_value'=>$result['description'],
	);
	$form['department']=array(
		'#title'=>'发生部门',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['department'],
	);
	$form['line']=array(
		'#title'=>'业务条线',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['line'],
	);
	$form['i_e']=array(
		'#title'=>'事件类型',
		'#type'=>'textfield',
		'#required'=>TRUE,
		'#default_value'=>$result['i_e'],
	);
	$form['submit']=array(
		'#type'=>'submit',
		'#value'=>'提交',
		'#submit'=>array('excel_edit_form_sumbit'),
	);
	return $form;
}

function excel_edit_form_sumbit($form,$form_state){
	$id=$_GET['id'];
	var_dump($id);
	$result=db_update('excel')
    ->condition('id',$id)
    ->fields(array(
    	'name' => $form_state['values']['name'],
    	'status' => $form_state['values']['status'],
    	'rating' => $form_state['values']['rating'],
    	'description' => $form_state['values']['description'],
    	'department' => $form_state['values']['department'],
    	'line' => $form_state['values']['line'],
    	'i_e' => $form_state['values']['i_e'],
    ))
    ->execute();
	if ($result) {	
		drupal_set_message('添加成功');
	}else{
		drupal_set_message('添加失败','error');
	}
}